# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-neural-search-plugin
pkgver=2.11.0.0
pkgrel=1
_opensearchver=2.11.0
_jdkver=11
pkgdesc="OpenSearch Neural Search Plugin"
arch=('loong64' 'x86_64')
# No docs website available yet
url="https://github.com/opensearch-project/neural-search"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/opensearch-project/neural-search/archive/${pkgver}.tar.gz"
)
sha256sums=('bf3c4a962fea42660151cb2a259369bc9d89df1051d517983603d2671f5074d9')

build() {
  cd "neural-search-${pkgver}"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"
  # integTest (Reaper) requires JDK 14
  ./gradlew build \
    --exclude-task "integTest" \
    --exclude-task "jacocoTestReport" \
    --exclude-task "jacocoTestCoverageVerification"
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-neural-search"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-neural-search"
  unzip "${srcdir}/neural-search-${pkgver}/build/distributions/opensearch-neural-search-${pkgver}.zip"

  install -Dm644 "${srcdir}/neural-search-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
